package com.bms.service;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bms.bean.User;
import com.bms.dao.UserDao;

@Service
public class UserService {
	
	@Resource
	private UserDao userDao;
	
	public long addUser(Date birthDay, /*Date createDate,*/ String mobileNo,
			String nickName, String passWord, Date registrationDate,
			String userEmail, int userSex, int userStatus, long roleId) {
		
		String userId = userDao.getUserSequence();
		
		User user = new User();
		user.setUserId(Long.valueOf(userId));
		user.setBirthDay(birthDay);
		/*user.setCreateDate(createDate);*/
		user.setMobileNo(mobileNo);
		user.setNickName(nickName);
		user.setPassWord(passWord);
		user.setRegistrationDate(registrationDate);
		user.setUserEmail(userEmail);
		user.setUserSex(userSex);
		user.setUserStatus(userStatus);
		user.setRoleId(roleId);
		
		userDao.addUser(user);
		return Long.valueOf(userId);
	}
	
	public void updateUserNotValidate(String userId,int userStatus,String nickName,String mobileNo,Date birthDay,int userSex,String userPic300){
		User user = userDao.getUserById(userId,0);
		
		user.setUserStatus(userStatus);
		user.setNickName(nickName);
		user.setMobileNo(mobileNo);
		user.setBirthDay(birthDay);
		user.setUserSex(userSex);
		user.setUserPic300(userPic300);
		
		userDao.updateUser(user);
	}
	
	public User updateUser(String userId,int userStatus,String nickName,String mobileNo,Date birthDay,int userSex,String userPic300,String userPic30){
		User user = userDao.getUserById(userId,1);
		
		user.setUserStatus(userStatus);
		user.setNickName(nickName);
		user.setMobileNo(mobileNo);
		user.setBirthDay(birthDay);
		user.setUserSex(userSex);
		user.setUserPic300(userPic300);
		user.setUserPic30(userPic30);
		userDao.updateUser(user);
		
		return user;
	}
}
